package elearning.controller.admin.regist;

import java.util.List;
import java.util.logging.Logger;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.util.BeanUtil;

import com.google.appengine.api.datastore.Key;

import elearning.model.Exam;
import elearning.model.Question;
import elearning.service.ElearningService;

public class EditController extends Controller {

	@SuppressWarnings("unused")
	private static final Logger logger = Logger.getLogger(EditController.class
			.getName());

	private ElearningService service = new ElearningService();

	@Override
	public Navigation run() {
		Exam exam;
		Key key = asKey("key");
		Long version = asLong("version");
		if (key != null) {
			exam = service.get(key, version);
			sessionScope("exam", exam);
		} else {
			exam = sessionScope("exam");
		}
		BeanUtil.copy(exam, request);
		List<Question> list = service.getQuestionByExam(exam.getKey());
		requestScope("questionList", list);
		return forward("edit.jsp");
	}
}
